package net.phoenix.repository.dao.mysql;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.text.MessageFormat;

import net.phoenix.repository.dao.ReferenceValueDao;
import net.phoenix.repository.data.NodePropertyData;

/**
 * 
* Jigsaw server
* 
* @author    <a href="shamphone@gmail.com">Li XiongFeng</a>
* @date      2012-9-30
* @version   1.0.0
 */
public class MysqlReferenceValueDao extends ReferenceValueDao {

	
	public NodePropertyData[] findReferenceByNode(String nodeID, int fromIndex, int pageSize) throws SQLException {
		PreparedStatement command = null;
		try {
			command = connection.prepareStatement(toMysqlRangeQuery(this.makeSelQuery(nodeID)));
			command.setInt(1, fromIndex );
			command.setInt(2, pageSize);
			NodePropertyData[] result = this.retrieve(command);
			return result;
		} finally {
			this.close(command);
		}
	}

	/**
	 * @Todo 支持根据Name来过滤
	 * @param nodeID
	 * @param name
	 * @param fromIndex
	 * @param pageSize
	 * @return
	 * @throws SQLException
	 */
	public NodePropertyData[] findReferenceByNode(String nodeID, String name, int fromIndex, int pageSize) throws SQLException {
		PreparedStatement command = null;
		try {
			command = connection.prepareStatement(toMysqlRangeQuery(this.makeSelQuery(nodeID)));
			command.setInt(1, fromIndex );
			command.setInt(2, pageSize);
			NodePropertyData[] result = this.retrieve(command);
			return result;
		} finally {
			this.close(command);
		}
	}
}
